﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.BranchCenter.BLL;

namespace ZHDJ.BranchCenter.Module.PartyRepresentative
{
    public partial class PartyRepresentativeStudioDesc : PageBase
    {
        #region 属性
        /// <summary>
        /// 是否和个人中心共用
        /// </summary>
        public override bool IsCommonPage
        {
            get
            {
                return true;
            }
        }
        #endregion
        #region ViewPower
        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                //return IsPersonalCenter? "PartyRepresentativeStudioAdd_p" : "PartyRepresentativeStudioAdd";
                return "PartyRepresentativeStudioAdd";
            }
        }

        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void LoadData()
        {
            if (!CheckPageRight())
            {
                //Response.Clear();
                Response.Write("未开通党代表工作室，如要开通请联系网站管理员");
                Response.End();
            }
        }

        public bool CheckPageRight()
        {
            var rs = true;
            if (!IsPersonalCenter && DB.PartyRepresentativeStudios.Count(a => a.ObjectID == BranchID) < 1)
            {
                rs = false;
            }
            else if (IsPersonalCenter && DB.PartyRepresentativeStudios.Count(a => a.ObjectID == CurrentUser.LoginID) < 1)
            {
                rs = false;
            }
            if (rs)
            {
                var objectid = !IsPersonalCenter ? BranchID : CurrentUser.LoginID;
                var temp = DB.PartyRepresentativeStudios.First(a => a.ObjectID == objectid);
                Region2.IFrameUrl= "PartyRepresentativeStudioEdit.aspx?IsPersonalCenter=" + (IsPersonalCenter?"1":"0")+"&id="+temp.ID;
                return true;
            }
            return false;
        }
    }
}